/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisos.Controle;

import java.io.Serializable;
import java.util.List;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import sisos.DAO.IServicoDAO;
import sisos.DAO.ServicoDAO;
import sisos.DAO.SisOSDAOException;
import sisos.Modelo.Servico;

/**
 *
 * @author FLAVIOFAV
 */
public class ControleServico implements Serializable{
    private Servico servico;
    
    private DataModel model;
    
    public String novoServico(){
        this.setServico(new Servico());
        return "cadastroServico";
    }
    
    public void limparServico(){
        this.setServico(new Servico());
    }
    
    public String listaServico(){
        //this.setServico(new Servico());
        return "liServico";
    }
    
    public List<Servico> listaServicos() throws SisOSDAOException{
        IServicoDAO idao = new ServicoDAO();
        return idao.todosServicos();
    }
    
    public Servico pegaServicoEditarOuDeletar(){
        Servico servico = (Servico) model.getRowData();
        return servico;
    }
    
    public String editar() throws SisOSDAOException{
        //Servico servico = pegaServicoEditarOuDeletar();
        //setServico(servico);
        return "editarServico";
    }
    
    public void update() throws SisOSDAOException{
        IServicoDAO idao = new ServicoDAO();
        idao.atualizar(servico);
        //return "sucessoAtualizacao";
    }
    
    public String excluir() throws SisOSDAOException{
        IServicoDAO idao = new ServicoDAO();
        Servico servico = pegaServicoEditarOuDeletar();
        idao.excluir(servico);
        return "sucessoExclusao";
    }
    
    public void salvar() throws SisOSDAOException{
        IServicoDAO idao = new ServicoDAO();
        idao.salvar(servico);
        //return "sucessoSalvar";
    }
    
    public String voltar(){
        return "voltar";
    }
    
    public String home(){
        return "home";
    }
    
    public String listarServico(){
        return "listarServico";
    }
    
    

    /**
     * @return the servico
     */
    public Servico getServico() {
        return servico;
    }

    /**
     * @param servico the servico to set
     */
    public void setServico(Servico servico) {
        this.servico = servico;
    }
}
